package com.dms.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.dms.dao.TeacherDao;
import com.dms.model.Teacher;

@Repository
public class TeacherDaoImpl extends BaseDaoImpl implements TeacherDao {

	@Override
	public Teacher getTeacher(String hql) {	
		return (Teacher) getSession().createQuery(hql).uniqueResult();
	}

	@Override
	public void updateTeacher(Teacher teacher) {
		Session session=this.getSession();
		session.merge(teacher);
		session.flush();
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Teacher> getTeachers(String hql) {
		return getSession().createQuery(hql).list();
	}

	@Override
	public void save(Teacher teacher) {
		this.getSession().save(teacher);
		
	}

	@Override
	public void delete(int id) {
		Session session=this.getSession();
		session.delete(session.get(Teacher.class, id));
		session.flush();
	}

	

}
